<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="订单id" prop="orderId">
        <el-input v-model="queryParams.orderId" placeholder="请输入订单id" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="用户id" prop="userId">
        <el-input v-model="queryParams.userId" placeholder="请输入用户id" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="手机号" prop="phone">
        <el-input v-model="queryParams.phone" placeholder="请输入手机号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="等级" prop="memberLevel">
        <el-select v-model="queryParams.memberLevel" placeholder="请选择等级" clearable filterable>
          <el-option label="VIP" :value="1">
          </el-option>
          <el-option label="SVIP" :value="2">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="类型" prop="type">
        <el-select v-model="queryParams.type" placeholder="请输入类型" clearable @keyup.enter.native="handleQuery">
          <el-option v-for="item in DictData.distribution" :key="item.value" :label="item.name" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="开始时间" prop="createStartTime">
        <el-date-picker v-model="queryParams.createStartTime" type="date" placeholder="请选择开始时间" clearable
          :editable="false" value-format="yyyy-MM-dd" @keyup.enter.native="handleQuery">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="createEndTime">
        <el-date-picker v-model="queryParams.createEndTime" type="date" placeholder="请选择结束时间" clearable
          :editable="false" value-format="yyyy-MM-dd" @keyup.enter.native="handleQuery">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['system:order:add']">新增</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <!-- <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:order:export']">导出</el-button> -->
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="订单id" align="center" prop="orderId" />
      <el-table-column label="消费者" align="center" prop="userId">
        <template slot-scope='{row}'>
          <div class="user-container">
            <div class="user-img">
              <image-preview :src="row.consumerAvatar" height="50px" width="50px"></image-preview>
            </div>
            <div class="user-info">
              <span>{{ row.consumerNickName }}</span>
              <span>{{ row.consumerPhonenumber }}</span>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="奖励用户" align="center" prop="userId">
        <template slot-scope='{row}'>
          <div class="user-container">
            <div class="user-img">
              <image-preview :src="row.avatar" height="50px" width="50px"></image-preview>
            </div>
            <div class="user-info">
              <span>{{ row.nickName }}</span>
              <span>{{ row.phonenumber }}</span>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="等级名称" align="center" prop="memberName" />
      <el-table-column label="佣金金额" align="center" prop="amount" />
      <el-table-column label="奖励类型名称" align="center" prop="typeName" />
      <el-table-column label="结算状态" align="center" prop="status">
        <template slot-scope='{row}'>
          {{ row.status == 1 ? '未结算' : '已结算' }}
        </template>
      </el-table-column>
      <el-table-column label="类型" align="center" prop="type">
        <template slot-scope='{row}'>
          {{ forrmatterEnmu(DictData.distribution, row.type) }}
        </template>
      </el-table-column>
      <el-table-column label="实付金额" align="center" prop="payMoney" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="150" />
      <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['system:order:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['system:order:remove']">删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改订单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户id" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户id" />
        </el-form-item>
        <el-form-item label="用户姓名" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入用户姓名" />
        </el-form-item>
        <el-form-item label="用户手机号" prop="phoneNumber">
          <el-input v-model="form.phoneNumber" placeholder="请输入用户手机号" />
        </el-form-item>
        <el-form-item label="实付金额" prop="payMoney">
          <el-input v-model="form.payMoney" placeholder="请输入实付金额" />
        </el-form-item>
        <el-form-item label="支付时间" prop="paymentTime">
          <el-date-picker clearable v-model="form.paymentTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择支付时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="配送费" prop="deliveryCost">
          <el-input v-model="form.deliveryCost" placeholder="请输入配送费" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="是否删除" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入是否删除" />
        </el-form-item>
        <el-form-item label="商户订单号" prop="outTradeNo">
          <el-input v-model="form.outTradeNo" placeholder="请输入商户订单号" />
        </el-form-item>
        <el-form-item label="微信支付订单号" prop="transactionId">
          <el-input v-model="form.transactionId" placeholder="请输入微信支付订单号" />
        </el-form-item>
        <el-form-item label="商户退款单号" prop="outRefundNo">
          <el-input v-model="form.outRefundNo" placeholder="请输入商户退款单号" />
        </el-form-item>
        <el-form-item label="收货人姓名" prop="receiveName">
          <el-input v-model="form.receiveName" placeholder="请输入收货人姓名" />
        </el-form-item>
        <el-form-item label="收货地址" prop="receiveAddress">
          <el-input v-model="form.receiveAddress" placeholder="请输入收货地址" />
        </el-form-item>
        <el-form-item label="收货人电话" prop="receivePhonenum">
          <el-input v-model="form.receivePhonenum" placeholder="请输入收货人电话" />
        </el-form-item>
        <el-form-item label="收货地址经度" prop="receiveLongitude">
          <el-input v-model="form.receiveLongitude" placeholder="请输入收货地址经度" />
        </el-form-item>
        <el-form-item label="收货地址纬度" prop="receiveLatitude">
          <el-input v-model="form.receiveLatitude" placeholder="请输入收货地址纬度" />
        </el-form-item>
        <el-form-item label="发货时间" prop="sendTime">
          <el-date-picker clearable v-model="form.sendTime" type="date" value-format="yyyy-MM-dd" placeholder="请选择发货时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="收货时间" prop="receiveTime">
          <el-date-picker clearable v-model="form.receiveTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择收货时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="收货备注" prop="receiveRemark">
          <el-input v-model="form.receiveRemark" placeholder="请输入收货备注" />
        </el-form-item>
        <el-form-item label="收货确认图片" prop="receiveImgUrl">
          <el-input v-model="form.receiveImgUrl" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="会员卡id" prop="memberId">
          <el-input v-model="form.memberId" placeholder="请输入会员卡id" />
        </el-form-item>
        <el-form-item label="本单获取积分" prop="gainIntegral">
          <el-input v-model="form.gainIntegral" placeholder="请输入本单获取积分" />
        </el-form-item>
        <el-form-item label="本单扣除积分" prop="deductIntegral">
          <el-input v-model="form.deductIntegral" placeholder="请输入本单扣除积分" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getRoyaltyRecordPage } from "@/api/system/commission/distribution";
import { forrmatterEnmu } from "@/utils/index";

export default {
  name: "Order",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderId: null,
        userId: null,
        phone: null,
        memberLevel: null,
        type: null,
        createStartTime: null,
        createEndTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    forrmatterEnmu,
    /** 查询订单列表 */
    getList() {
      this.loading = true;
      debugger
      getRoyaltyRecordPage(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        userName: null,
        phoneNumber: null,
        payMoney: null,
        paymentTime: null,
        deliveryCost: null,
        orderStatus: null,
        createTime: null,
        updateTime: null,
        remark: null,
        delFlag: null,
        outTradeNo: null,
        transactionId: null,
        outRefundNo: null,
        receiveName: null,
        receiveAddress: null,
        receivePhonenum: null,
        receiveLongitude: null,
        receiveLatitude: null,
        sendTime: null,
        receiveTime: null,
        orderType: null,
        deliveryType: null,
        receiveRemark: null,
        receiveImgUrl: null,
        memberId: null,
        gainIntegral: null,
        deductIntegral: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      // this.reset();
      // const id = row.id || this.ids
      // getOrder(id).then(response => {
      //   this.form = response.data;
      //   this.open = true;
      //   this.title = "修改订单";
      // });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            // updateOrder(this.form).then(response => {
            //   this.$modal.msgSuccess("修改成功");
            //   this.open = false;
            //   this.getList();
            // });
          } else {
            // addOrder(this.form).then(response => {
            //   this.$modal.msgSuccess("新增成功");
            //   this.open = false;
            //   this.getList();
            // });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除订单编号为"' + ids + '"的数据项？').then(function () {
        // return delOrder(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/order/export', {
        ...this.queryParams
      }, `order_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style lang="less" scoped>
.user-container {
  display: flex;
  justify-content: center;
  align-items: center;

  .user-img {
    margin-right: 10px;
  }

  .user-info {
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    align-items: center;
  }
}
</style>